package com.srmt.common.ratelimit.exception;

/**
 * 限流异常
 * 当请求超过QPS限制且无法在指定时间内获取令牌时抛出
 * 
 * @author SRMT Development Team
 * @since 1.0.0
 */
public class RateLimitException extends RuntimeException {
    
    private final String api;
    private final int qpsLimit;
    private final long waitTime;
    
    /**
     * 构造函数
     * 
     * @param message 异常消息
     */
    public RateLimitException(String message) {
        super(message);
        this.api = null;
        this.qpsLimit = 0;
        this.waitTime = 0;
    }
    
    /**
     * 构造函数
     * 
     * @param api API端点
     * @param qpsLimit QPS限制
     * @param waitTime 需要等待的时间(毫秒)
     */
    public RateLimitException(String api, int qpsLimit, long waitTime) {
        super(String.format("Rate limit exceeded for API [%s], QPS limit: %d, estimated wait time: %d ms", 
                           api, qpsLimit, waitTime));
        this.api = api;
        this.qpsLimit = qpsLimit;
        this.waitTime = waitTime;
    }
    
    /**
     * 构造函数
     * 
     * @param message 异常消息
     * @param cause 原因异常
     */
    public RateLimitException(String message, Throwable cause) {
        super(message, cause);
        this.api = null;
        this.qpsLimit = 0;
        this.waitTime = 0;
    }
    
    public String getApi() {
        return api;
    }
    
    public int getQpsLimit() {
        return qpsLimit;
    }
    
    public long getWaitTime() {
        return waitTime;
    }
}